package com.zm.Study06_OutputStreamWriter;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class OutputStreamWriterDemo01 {
    public OutputStreamWriterDemo01() throws FileNotFoundException {
    }

    OutputStreamWriter osw=new OutputStreamWriter(new FileOutputStream("D:\\project\\IDEAPROJECT\\JavaIO\\src\\main\\resources\\static\\ReaderAndWriter\\osw.txt"));



    public static void main(String[] args) throws IOException {
        OutputStreamWriterDemo01 outputStreamWriterDemo01=new OutputStreamWriterDemo01();
        //outputStreamWriterDemo01.oneByte();
        //outputStreamWriterDemo01.charList();
        //outputStreamWriterDemo01.partOfCharList(1,3); //坐标从0开始
        //outputStreamWriterDemo01.writeString();
        outputStreamWriterDemo01.writePartOfString(1,3);
    }

    public  void oneByte() throws IOException {
        osw.write(97); //里面有缓冲
        osw.flush(); //刷新流
        osw.close(); //关闭流之前会先刷新
    }

    public void charList() throws IOException {
        char[] chars={'a','b','c','d','e'};
        osw.write(chars);
        osw.close();
    }

    public void partOfCharList(int start,int end) throws IOException {
        char[] chars={'a','b','c','d','e'};
        osw.write(chars,start,end);
        osw.close();
    }

    public void writeString () throws IOException {
        String str="abcd";
        osw.write(str);
        osw.close();
    }
    public void writePartOfString (int start,int end) throws IOException {
        String str="abcd";
        osw.write(str,start,end);
        osw.close();
    }
}
